// 设置时间
let setTime = function() {
  let res = getCurrentTime();
  $(".currentTime").text(res.currentTime);
  $(".currentDate").text(res.currentDate);
  $(".currentWeek").text(res.currentWeek);
};
setTime();

// 定时更新时间
let timing = function() {
  setInterval(function() {
    setTime();
  }, 1000);
};
timing();


//省市县选择
$("#cityChooseBox").cityChoose(function(id,name){
  $(".city").text(name);
  let url = getAreaMapUrl(id);
  mapChart(url);
})
$(".site").click(function(e){
  e.stopPropagation();
  $("#cityChooseBox").toggle();
})
document.onclick = function(){
  $("#cityChooseBox").hide();
}





const myChart1 = echarts.init(document.getElementById("distributeByTypeChart"));
const myChart2 = echarts.init(document.getElementById("faultAnalysisChart"));
const myChart3 = echarts.init(document.getElementById("mapChart"));
const myChart4 = echarts.init(document.getElementById("situationAnalysisChart"));
const myChart5 = echarts.init(document.getElementById("distributeByStatusChart"));
const myChart6 = echarts.init(document.getElementById("distributeByServerChart"));
const myChart7 = echarts.init(document.getElementById("rateChart"));
// 按装备类型分布
const distributeByTypeChart = function() {
  myChart1.setOption(myChart_option1());
};
distributeByTypeChart();

// 近一年故障分析
const faultAnalysisChart = function() {
  myChart2.setOption(myChart_option2());
};
faultAnalysisChart();

//map
const mapChart = function(url) {
  $.get(`../${url}`,function(geoJson){
    echarts.registerMap('shanghai', geoJson);
    myChart3.setOption(myChart_option3());
  })
};
mapChart(url='china/china.json');

//个行政区故障情况分析
const situationAnalysisChart = function() {
  myChart4.setOption(myChart_option4());
};
situationAnalysisChart();

//故障状态分布
const distributeByStatusChart = function() {
  myChart5.setOption(myChart_option5());
};
distributeByStatusChart();

//保修服务分布
const distributeByServerChart = function() {
  myChart6.setOption(myChart_option6());
};
distributeByServerChart();

//rate分类
const rateChart = function() {
  myChart7.setOption(myChart_option7());
};
rateChart();

//图例适应屏幕变化

const chartResize = function(){
  myChart1.resize();
  myChart2.resize();
  myChart3.resize();
  myChart4.resize();
  myChart5.resize();
  myChart6.resize();
  myChart7.resize();
}
window.onresize = debounce(chartResize,500);


